/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DropMode;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
/*
/*
 * productos.java
 *
 * Created on 24-feb-2011, 19:20:37
 */
 import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Victor Manuel
 */
public class productos extends javax.swing.JFrame {
 private ResultSet sr;
 private ResultSet sr2;
 private ResultSet sr3;
  private ResultSet sr4;
 static double sumatotal=0;

 private Login l= new  Login();
    /** Creates new form productos */
    public productos() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        mostrar = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        agregarl = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        confirmarcompra = new javax.swing.JButton();
        Eliminarlista = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        carrito = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        cambiarcontraseña = new javax.swing.JButton();
        filtro = new javax.swing.JButton();
        busqueda = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        productos = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        filtrar = new javax.swing.JTable();
        agregar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();

        mostrar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "Marca", "Clave", "precio", "cantidad"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        mostrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mostrarMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(mostrar);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(153, 153, 255));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        agregarl.setText("Agregar a Lista");
        agregarl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregarlActionPerformed(evt);
            }
        });
        jPanel1.add(agregarl, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 190, -1, -1));

        jLabel1.setFont(new java.awt.Font("Tahoma", 3, 14));
        jLabel1.setText("Agregados a la compra.");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 350, -1, -1));

        confirmarcompra.setText("Imprimir ticket ");
        confirmarcompra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmarcompraActionPerformed(evt);
            }
        });
        jPanel1.add(confirmarcompra, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 520, -1, -1));

        Eliminarlista.setText("Eliminar");
        Eliminarlista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EliminarlistaActionPerformed(evt);
            }
        });
        jPanel1.add(Eliminarlista, new org.netbeans.lib.awtextra.AbsoluteConstraints(161, 520, -1, -1));

        carrito.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "Marca", "Clave", "Precio", "idcompras", "Cantidad"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        carrito.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                carritoMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(carrito);

        jPanel1.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 380, 400, 129));

        jLabel2.setFont(new java.awt.Font("Tahoma", 3, 14));
        jLabel2.setText("Tabla de productos.");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 148, 30));
        jPanel1.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 340, 430, 10));

        cambiarcontraseña.setText("Cambiar contraseña");
        cambiarcontraseña.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cambiarcontraseñaActionPerformed(evt);
            }
        });
        jPanel1.add(cambiarcontraseña, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 10, -1, -1));

        filtro.setText("Busqueda");
        filtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filtroActionPerformed(evt);
            }
        });
        jPanel1.add(filtro, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 220, -1, -1));

        busqueda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                busquedaActionPerformed(evt);
            }
        });
        jPanel1.add(busqueda, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 220, 130, -1));

        productos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "Marca", "Clave", "precio", "Existencia"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        productos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                productosMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(productos);

        jPanel1.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 400, 140));

        filtrar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "Marca", "Clave", "precio", "cantidad"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        filtrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                filtrarMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(filtrar);

        jPanel1.add(jScrollPane4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 250, 400, 50));

        agregar.setText("Agregar a lista");
        agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregarActionPerformed(evt);
            }
        });
        jPanel1.add(agregar, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 310, -1, -1));

        jLabel3.setIcon(new javax.swing.ImageIcon("C:\\Users\\Victor Manuel\\Pictures\\W5CALAAAY5CA7DQNAUCARHW2U3CA1DNK5DCAKT9VXUCA60FDMCCAUG5KG2CAK3EDN3CAITEPFNCAME44UNCAGY8RWOCA4MVC5ACADBNKMZCAHQWOB0CALC838LCAC9YS9JCAZL5C27CAOXVUMN.jpg")); // NOI18N
        jLabel3.setText("jLabel3");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, -1, 180));
        jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 520, 80, -1));

        jLabel4.setText("Total:");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 520, -1, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 450, 550));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void agregarlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregarlActionPerformed
         try {
String n=JOptionPane.showInputDialog("Cantidad: ");
cantP = Integer.parseInt(n);
   @SuppressWarnings("static-access")
   java.sql.Statement st2 = l.conexion.createStatement();
   st2.executeUpdate("INSERT INTO compras (nombres,marcas,claves,precios,cantidad)  VALUES ('"+agregarnom+"','"+agregarmar+"','"+agregarcla+"','"+precios+"','"+cantP+"')");
    st2.executeUpdate("update productos set cantidad=cantidad +"+(-cantP)+" where clave='"+seleccionar+"'");
         } catch (SQLException ex) {
            Logger.getLogger(Agregar.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null,"Producto agotado");
        }
//   new productos().setVisible(true);
//   this.dispose();

    try {

   @SuppressWarnings("static-access")
   java.sql.Statement st2 = l.conexion.createStatement();
   st2.executeUpdate("INSERT INTO comprados (nombres,marcas,claves,precios)  VALUES ('"+agregarnom+"','"+agregarmar+"','"+agregarcla+"','"+precios+"')");
//   st2.executeUpdate("select cantidad from productos where nombre");
//
//   st2.executeUpdate("update  productos set cantidad) ;
//           cant=Integer.parseInt("cantidad");
   } catch (SQLException ex) {
            Logger.getLogger(Agregar.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null,"Ya se ha agregado ese producto");
        }
   new productos().setVisible(true);
   this.dispose();
   
        // TODO add your handling code here:
    }//GEN-LAST:event_agregarlActionPerformed

    private void confirmarcompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmarcompraActionPerformed




   
    Map mapa = new HashMap();
        mapa.put("suma",33);
        mapa.put("nombre","clarinete");
        Connection c = null;
        try {
            c = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/desarrollo","root","");
        } catch (SQLException ex) {
            Logger.getLogger(productos.class.getName()).log(Level.SEVERE, null, ex);
        }


        JasperReport reporte = null;
            try {
                reporte = JasperCompileManager.compileReport("C:/Users/Victor Manuel/Documents/NetBeansProjects/basedeDatos/ticketcompras/reportecompra.jrxml");
            } catch (JRException ex) {
                Logger.getLogger(productos.class.getName()).log(Level.SEVERE, null, ex);
            }
        JasperPrint print = null;
            try {
                print = JasperFillManager.fillReport(reporte, mapa, c);
            } catch (JRException ex) {
                Logger.getLogger(productos.class.getName()).log(Level.SEVERE, null, ex);
            }

        JasperViewer visor= new JasperViewer(print);


        visor.setVisible(true);


        try {


      @SuppressWarnings("static-access")
      java.sql.Statement st2 = l.conexion.createStatement();
      st2.execute("delete FROM  compras ");
      new productos().setVisible(true);
      this.dispose();
      } catch (SQLException ex) {
      Logger.getLogger(productos.class.getName()).log(Level.SEVERE, null, ex);
        }
//         TODO add your handling code here:
    }//GEN-LAST:event_confirmarcompraActionPerformed

    private void mostrarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mostrarMouseClicked


    agregarnom=mostrar.getValueAt(mostrar.getSelectedRow(),0)+"";
    agregarmar=mostrar.getValueAt(mostrar.getSelectedRow(),1)+"";
    agregarcla=mostrar.getValueAt(mostrar.getSelectedRow(),2)+"";
    precios=Integer.parseInt(mostrar.getValueAt(mostrar.getSelectedRow(),3)+"");
    cantidad=Integer.parseInt(mostrar.getValueAt(mostrar.getSelectedRow(),4)+"");
    System.out.println(agregarnom);
    System.out.println(agregarmar);
    System.out.println(agregarcla);
    System.out.println(precios);
    System.out.println(cantidad);
    // TODO add your handling code here:
    }//GEN-LAST:event_mostrarMouseClicked

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
Eliminarlista.setVisible(false);
        agregarl.setVisible(false);
        agregar.setVisible(false);
       int cont=0;
       try {
     @SuppressWarnings("static-access")
          java.sql.Statement st = l.conexion.createStatement();
           sr=  st.executeQuery("SELECT nombres,marca,clave,precio,cantidad FROM  productos ");
           while  (sr.next()){

          String nombre=sr.getString("nombres");
          String marca=sr.getString("marca");
          String clave=sr.getString("clave");
          int precio=sr.getInt("precio");
          int cantidads=sr.getInt("cantidad");
          DefaultTableModel tm= (DefaultTableModel) productos.getModel();
          Object nuevo[]={"","","","",""};
          tm.addRow(nuevo);
          productos.setValueAt(nombre, cont, 0);
          productos.setValueAt(marca, cont, 1);
          productos.setValueAt(clave, cont, 2);
          productos.setValueAt(precio, cont, 3);
          productos.setValueAt(cantidads, cont, 4);
          cont++;
          System.out.println(nombre+marca+clave+precio+cantidads);

        }
        sr.close();
       } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
//
int cont2=0;
    try {

      @SuppressWarnings("static-access")
      java.sql.Statement st3 = l.conexion.createStatement();
      sr2=  st3.executeQuery("select nombres,marcas,claves,precios,idcompras,cantidad FROM  compras ");
      while  (sr2.next()){
      String nombre=sr2.getString("nombres");
      String marca=sr2.getString("marcas");
      String clave=sr2.getString("claves");
      int precio=sr2.getInt("precios");
      int idc=sr2.getInt("idcompras");
       int cant=sr2.getInt("cantidad");


    DefaultTableModel tm2= (DefaultTableModel) carrito.getModel();
    Object nuevo2[]={"","","","",""};
    tm2.addRow(nuevo2);
    carrito.setValueAt(nombre,cont2, 0);
    carrito.setValueAt(marca,cont2,  1);
    carrito.setValueAt(clave,cont2, 2);
    carrito.setValueAt(precio,cont2, 3);
    carrito.setValueAt(idc,cont2, 4);
    carrito.setValueAt(cant,cont2, 5);
    cont2++;
    System.out.println(nombre+marca+clave+precio);
     }
      sr2.close();

        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }



        try {
        java.sql.Statement st = l.conexion.createStatement();
       ResultSet r= st.executeQuery("select sum(precios) from compras" );
            r.next();
          jTextField1.setText(r.getString(1));




               } catch (SQLException ex) {
           ex.printStackTrace();
        }



// TODO add your handling code here:
    }//GEN-LAST:event_formWindowOpened

    private void EliminarlistaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EliminarlistaActionPerformed

        try {

        java.sql.Statement  st5 = Login.conexion.createStatement();
          System.out.println(eliminar+"Eliminando");
        
        st5.executeUpdate("update productos set cantidad=cantidad +"+carrito.getValueAt(carrito.getSelectedRow(),5).toString()+" where clave='"+eliminar+"'");
        int x=st5.executeUpdate("delete from compras where idcompras='"+eliminar2+"'");
        new productos().setVisible(true);
        this.dispose();
        } catch (SQLException ex) {
        Logger.getLogger(tienda.class.getName()).log(Level.SEVERE, null, ex);
        }
// TODO add your handling code here:
    }//GEN-LAST:event_EliminarlistaActionPerformed

    private void carritoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_carritoMouseClicked
  eliminar=carrito.getValueAt(carrito.getSelectedRow(),2).toString();
eliminar2=carrito.getValueAt(carrito.getSelectedRow(),4).toString();
  
  Eliminarlista.setVisible(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_carritoMouseClicked

    private void cambiarcontraseñaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cambiarcontraseñaActionPerformed
  new contras().setVisible(true);
    this.dispose();

        // TODO add your handling code here:
    }//GEN-LAST:event_cambiarcontraseñaActionPerformed

    private void filtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filtroActionPerformed

//mostrar.setVisible(true);
        int cont3=0;
    try {
        // productos.setModel(new  javax.swing.table.DefaultTableModel());

          @SuppressWarnings("static-access")
          java.sql.Statement st5 = l.conexion.createStatement();
           sr3=  st5.executeQuery("SELECT * FROM  productos where nombres='"+busqueda.getText()+"'");
          while  (sr3.next()){



          String nombre2=sr3.getString("nombres");
//          if (busqueda.getText()!="nombres"){
//              System.out.print("no existe");
//          }
          String marca2=sr3.getString("marca");
          String clave2=sr3.getString("clave");
          int precio2=sr3.getInt("precio");
          int cantidadss=sr3.getInt("cantidad");
          DefaultTableModel tm4= (DefaultTableModel) filtrar.getModel();
          Object nuevo4[]={"","","","",""};
          tm4.addRow(nuevo4);
          filtrar.setValueAt(nombre2, cont3, 0);
          filtrar.setValueAt(marca2, cont3, 1);
          filtrar.setValueAt(clave2, cont3, 2);
          filtrar.setValueAt(precio2, cont3, 3);
          filtrar.setValueAt(cantidadss, cont3, 4);
          cont3++;
          System.out.println(nombre2+marca2+clave2+precio2+cantidadss);


    

        }
        sr3.close();
       } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);    }

//        // TODO add your handling code here:
    }//GEN-LAST:event_filtroActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed


           


           // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
new Login().setVisible(true);

        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

    private void productosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_productosMouseClicked
seleccionar=productos.getValueAt(productos.getSelectedRow(),2).toString();
        agregarl.setVisible(true);
agregar.setVisible(false);
        agregarnom=productos.getValueAt(productos.getSelectedRow(),0)+"";
    agregarmar=productos.getValueAt(productos.getSelectedRow(),1)+"";
    agregarcla=productos.getValueAt(productos.getSelectedRow(),2)+"";
    precios=Integer.parseInt(productos.getValueAt(productos.getSelectedRow(),3)+"");
    cantidad=Integer.parseInt(productos.getValueAt(productos.getSelectedRow(),4)+"");
    System.out.println(agregarnom);
    System.out.println(agregarmar);
    System.out.println(agregarcla);
    System.out.println(precios);
    System.out.println(cantidad);

        // TODO add your handling code here:
    }//GEN-LAST:event_productosMouseClicked

    private void filtrarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_filtrarMouseClicked
seleccionar2=filtrar.getValueAt(filtrar.getSelectedRow(),2).toString();

        agregar.setVisible(true);
agregarl.setVisible(false);
        agregarnom2=filtrar.getValueAt(filtrar.getSelectedRow(),0)+"";
    agregarmar2=filtrar.getValueAt(filtrar.getSelectedRow(),1)+"";
    agregarcla2=filtrar.getValueAt(filtrar.getSelectedRow(),2)+"";
    precios2=Integer.parseInt(filtrar.getValueAt(filtrar.getSelectedRow(),3)+"");
   // cantidad2=Integer.parseInt(filtrar.getValueAt(filtrar.getSelectedRow(),4)+"");
    System.out.println(agregarnom2);
    System.out.println(agregarmar2);
    System.out.println(agregarcla2);
    System.out.println(precios2);
    System.out.println(cantidad2);

        // TODO add your handling code here:
    }//GEN-LAST:event_filtrarMouseClicked

    private void agregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregarActionPerformed
try {
String n=JOptionPane.showInputDialog("Cantidad: ");
cantP2 = Integer.parseInt(n);
   @SuppressWarnings("static-access")
   java.sql.Statement st2 = l.conexion.createStatement();
   st2.executeUpdate("INSERT INTO compras (nombres,marcas,claves,precios,cantidad)  VALUES ('"+agregarnom2+"','"+agregarmar2+"','"+agregarcla2+"','"+precios2+"','"+cantP2+"')");
   st2.executeUpdate("update productos set cantidad=cantidad +"+(-cantP2)+" where clave='"+seleccionar2+"'");
} catch (SQLException ex) {
            Logger.getLogger(Agregar.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null,"Ya se ha agregado ese producto");
        }
   new productos().setVisible(true);
   this.dispose();

    try {

   @SuppressWarnings("static-access")
   java.sql.Statement st2 = l.conexion.createStatement();
   st2.executeUpdate("INSERT INTO comprados (nombres,marcas,claves,precios)  VALUES ('"+agregarnom2+"','"+agregarmar2+"','"+agregarcla2+"','"+precios2+"')");
   } catch (SQLException ex) {
            Logger.getLogger(Agregar.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null,"Ya se ha agregado ese producto");
        }
   new productos().setVisible(true);
   this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_agregarActionPerformed

    private void busquedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_busquedaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_busquedaActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new productos().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Eliminarlista;
    private javax.swing.JButton agregar;
    private javax.swing.JButton agregarl;
    private javax.swing.JTextField busqueda;
    private javax.swing.JButton cambiarcontraseña;
    private javax.swing.JTable carrito;
    private javax.swing.JButton confirmarcompra;
    private javax.swing.JTable filtrar;
    private javax.swing.JButton filtro;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTable mostrar;
    private javax.swing.JTable productos;
    // End of variables declaration//GEN-END:variables
String agregarnom;
String agregarmar;
String agregarcla;
int precios;
int cantidad;
String agregarnom2;
String agregarmar2;
String agregarcla2;
int precios2;
int cantidad2;
int cantP;
int cantP2;
String eliminar;
String eliminar2;
String seleccionar;
String seleccionar2;
}
